package cn.szzsi.validator;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * Created by haotian on 2016/9/26.
 */
public class BusinessProductValidator extends Validator {

    @Override
    protected void validate(Controller c) {
        c.getFile();
        validateRequiredString("product.name", "msg", "商品名称不允许为空!");
        validateRequiredString("product.price", "msg", "销售价不允许为空!");
        validateRequiredString("product.marketPrice", "msg", "市场价不允许为空!");
        validateRequiredString("product.weight", "msg", "商品重量不允许为空!");
        validateRequiredString("weightUnit", "msg", "商品重量单位不允许为空!");
        validateRequiredString("product.isMarketable", "msg", "是否上架不允许为空!");
        validateRequiredString("product.isBest", "msg", "是否精品不允许为空!");
        validateRequiredString("product.isNew", "msg", "是否新品不允许为空!");
        validateRequiredString("product.isHot", "msg", "是否热销不允许为空!");
        validateRequiredString("product.productCategory_id", "msg", "所属分类不允许为空!");
        //validateRequiredString("product.brand_id", "msg", "商品品牌不允许为空!");

        //validateInteger("product.point", 0, 10000, "msg", "积分必须为零或正整数!");
        validateInteger("product.store", 0, 10000, "msg", "库存必须为零或正整数!");
    }

    @Override
    protected void handleError(Controller c) {
        c.renderJson();
    }

}
